﻿using ShortcutToolbox.Core;
using System;
using System.Collections.Generic;

namespace DNSProxyPlugin
{
    public class DNSProxyPlugin : IPlugin
    {
        public Guid ID
        {
            get { return Guid.Parse("{BD630BE2-2398-4646-B391-AE32DB9EE508}"); }
        }
        public string Version
        {
            get { return "0.1"; }
        }
        public string Name { get; set; }
        public string Description { get; set; }
        public string Catalog { get; set; } = PluginCatalogs.Network;
        public PluginStatus Status { get; set; } = PluginStatus.Visiable;
        public IList<IPluginMenu> Menus { get; set; } = new List<IPluginMenu>();
        public event EventHandler StatusChanged;

        private PluginMenu _SeperatorMenu;
        private PluginMenu _ConfigurationMenu;

        public DNSProxyPlugin()
        {
            Name = I18N.Current["DNSProxyPlugin.Name"];
            Description = I18N.Current["DNSProxyPlugin.Description"];
        }

        public void Init(IShortcutToolboxController controller)
        {
            _SeperatorMenu = new PluginMenu { Text = "-" };
            _ConfigurationMenu = new PluginMenu { Text = "DNSProxyPlugin.Menu.Configuration" };
            PluginMenu menu = new PluginMenu { Text = "DNSProxyPlugin.Menu.DNSProxy" };
            menu.SubItems.Add(_SeperatorMenu);
            menu.SubItems.Add(_ConfigurationMenu);
            Menus.Add(menu);
            _ConfigurationMenu.Click += OnConfigurationMenuClick;
        }

        private void OnConfigurationMenuClick(object sender, EventArgs e)
        {
            _ConfigurationMenu.Checked = !_ConfigurationMenu.Checked;
            _ConfigurationMenu.RaiseStatusChange(e);
        }

        public void Uninit()
        {

        }

        public virtual void RaiseStatusChange(EventArgs e)
        {
            StatusChanged?.Invoke(this, e);
        }
    }
}
